<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>login</title>
    <script th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script>
</head>
<body>
    <center>
        <h1>商务会员管理系统</h1>
        <form action="javascript:;"  method="post" onsubmit="return tologin();">
            用户名: <input name="name" type="text" th:value="${name}"/><br/>
            密码: <input name="password" type="password" th:value="${password}"/><br/>
            验证码:<input name="code">
            <br/>
            <img src="code" ><br/>
            <input type="submit" value="登录"/>
        </form>
    </center>

        <script>
            $("img").click(function () {
                $(this).attr('src','code?abc='+new Date().getTime());
            })
            function tologin(){
                var name =  $("[name = name]").val();
                var password =  $("[name = password]").val();
                var code =  $("[name = code]").val();
                if (name == '' || password=='') {
                    alert("请填写完整信息");
                    return false;
                }
                if (name.length<6 || password.length<6){
                    alert("用户名和密码至少为6位");
                    return false;
                }
                $.post("/info/login?name="+name+"&password="+password+"&code="+code,function (data) {

                    if (data!="成功"){
                        alert(data);
                    }else {
                        location.href='info/list';
                    }
                })
            }
        </script>
</body>
</html>